package com.kfm.base.thread.day03;

public class Demo19 {

    public static void main(String[] args) {
        MyRunnable runnable = new MyRunnable();

        for (int i = 0; i < 100; i++) {
            new Thread(runnable).start();
        }
    }
}

class MyRunnable implements Runnable{

    private volatile int count = 0;

    @Override
    public void run() {
        for (int i = 0; i < 1000; i++) {
            // 1.从共享数据中读取数据到本线程栈中.
            // 2.修改本线程栈中变量副本的值
            // 3. 会把本线程栈中变量副本的值赋值给共享数据.
            synchronized (this){
                count++;
            }
            System.out.println(count);
        }
    }

}
